home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 8 / FM Towns Free Software Collection 8.iso / t_os / artemis / artsrc2 / extwild.c < prev    next >
C/C++ Source or Header  |  1994-06-01  |  1KB  |  47 lines

  1. /*
  2.     extwild.c
  3.  
  4.     ワイルドカードの展開
  5. */
  6.  
  7. #include <stdio.h>
  8. #include <dos.h>
  9. #include <string.h>
  10. #include <malloc.h>
  11.  
  12. #include <ryosuke.h>
  13.  
  14. int extwildcard(char *wildcard, char *namebuf[], int maxnames)
  15.     /* 返値 : 見つかったファイルの個数(≦maxnames)                 */
  16.     /* 各ファイルネームを格納するための領域は逐一 malloc される。 */
  17.     {
  18.     char            *p,path[80],buf[80];
  19.     struct find_t    fdat;
  20.     bool             first;
  21.     uint            ret;
  22.     int                foundnum;
  23.                                     /* wildcard から パス名部分を取り出す */
  24.     strcpy(path,wildcard);
  25.     if ((p = strrchr(path, '\\')) != NULL)
  26.         *++p = '\0';
  27.     else
  28.         path[0] = '\0';
  29.  
  30.     for (first=YES,foundnum=0;  foundnum < maxnames;  first=NO,foundnum++) {
  31.         if (first)
  32.             ret = _dos_findfirst(wildcard, _A_NORMAL, &fdat);
  33.         else
  34.             ret = _dos_findnext(&fdat);
  35.         if (ret != 0)
  36.             break;
  37.  
  38.         strcpy(buf, path);
  39.         strcat(buf, fdat.name);
  40.         if ((namebuf[foundnum] = malloc(strlen(buf)+1)) == NULL)
  41.             break;
  42.         else
  43.             strcpy(namebuf[foundnum], buf);
  44.         }
  45.     return foundnum;
  46.     }
  47.